/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sync.local;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import sync.exceptions.MergeException;
import sync.merge.IMergeProvider;
import sync.online.PicasaWebAlbumMediaContentPicture;

/**
 *
 * @author zalem1
 */
public class FileSystemMergeProvider implements IMergeProvider {
    private HashMap<String, FileSystemMediaContentPicture> _mediaContentCollection = new HashMap<String, FileSystemMediaContentPicture>();
    HashMap<String, String> _contentOwnership;

    public FileSystemMergeProvider(HashMap<String, String> contentOwnership) {
        _contentOwnership = contentOwnership;
    }
    
    @Override
    public void changeLocalPath(String localPath, String newLocalPath) {
        synchronized (this) {
            FileSystemMediaContentPicture mediaContent = _mediaContentCollection.get(localPath);
            _mediaContentCollection.remove(localPath);
            _mediaContentCollection.put(newLocalPath, mediaContent);
        }
        
    }
    
    @Override
    public boolean isChanged(String localPath) {
        FileSystemMediaContentPicture mediaContent = getMediaContent(localPath);
        File mediaFile = new File(localPath);
        
        boolean fileModified = (mediaContent.getLastUpdated() == mediaFile.lastModified());
        return fileModified;
    }

    @Override
    public FileSystemMediaContentPicture getMediaContent(String localPath) {
        FileSystemMediaContentPicture mediaContent = _mediaContentCollection.get(localPath);
        if (mediaContent != null) return mediaContent;
        
        mediaContent = new FileSystemMediaContentPicture(localPath);
        return mediaContent;
    }

    @Override
    public boolean exists(String localPath) {
        File mediaFile = new File(localPath);
        return mediaFile.exists();
    }

    @Override
    public boolean isAlbum(String localPath) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean isPhoto(String localPath) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean isVideo(String localPath) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean isMedia(String localPath) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String getFilename(String localPath) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean isNew(String localPath) {
        return _mediaContentCollection.containsKey(localPath);
    }

    @Override
    public long getSize(String localPath) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String getMediaHash(String localPath) throws MergeException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public InputStream getInputStream(String localPath, final int length) throws MergeException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public OutputStream getOutputStream(String localPath) throws MergeException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void updateMetadata(String _localPath) {
        FileSystemMediaContentPicture mediaContent = getMediaContent(_localPath);
        File mediaFile = new File(_localPath);
        mediaContent.setLastUpdated(mediaFile.lastModified());
    }

    @Override
    public void delete() {
        throw new UnsupportedOperationException("Not supported yet.");
    }


    
}
